const Db = require('./db')
const vk = require('./vk')

class upload
{
  static async tx(ctx){
    let file = ctx.req.file
    let path = file.destination + '/' + file.filename
    ctx.body = vk.showData(200,{path},'上传成功')
  }
  
  static async pic(ctx){
    let file = ctx.req.file
    let path = file.destination + '/' + file.filename
    let data = {
      sql:"INSERT INTO vk_pic_list (path) VALUES (?)",
      values:[path]
    }
    let [err,res] = await Db.query(data)
    if(err){return ctx.body = vk.showData(500,err,'上传失败')}
    ctx.body = vk.showData(200,{path},'上传成功')
  }

  static async ueditor(ctx){
    let file = ctx.req.file
    let path = file.destination + '/' + file.filename
    ctx.body = vk.showData(200,{path},'上传成功')
  }
}

module.exports = upload